﻿namespace Vinno.Brand.Pack.Core
{
    public partial class BrandService
    {
        /// <summary>
        /// 获取 实体仓储对象
        /// </summary>
        private SalerStore SalerStore => ServiceProvider.GetService<SalerStore>();

        /// <summary>
        /// 获取 实体查询数据集
        /// </summary>
        public IQueryable<Saler> Salers => SalerStore.Entities;

        /// <summary>
        /// 根据编号查找
        /// </summary>
        /// <param name="id">数据实体编号</param>
        /// <returns>业务操作结果</returns>
        public async Task<OperationResult<SalerOutputDto>> FindSalerById(Guid id)
        {
            Check.NotEmpty(id, nameof(id));

            var outputDto = Salers.Where(o => o.Id.Equals(id)).ToOutput<Saler, SalerOutputDto>().FirstOrDefault();
            if (outputDto != null)
            {
                return await Task.FromResult(new OperationResult<SalerOutputDto>(OperationResultType.Success, "OK", outputDto));
            }

            return await Task.FromResult(new OperationResult<SalerOutputDto>(OperationResultType.NotFound, "Not Found", outputDto));
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="dtos">DTO信息</param>
        /// <returns>业务操作结果</returns>
        public async Task<OperationResult> CreateSalers(params SalerInputDto[] dtos)
        {
            return await SalerStore.InsertByDtoAsync(dtos);
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="dtos">DTO信息</param>
        /// <returns>业务操作结果</returns>
        public async Task<OperationResult> UpdateSalers(params SalerInputDto[] dtos)
        {
            return await SalerStore.UpdateByDtoAsync(dtos);
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="ids">数据实体编号</param>
        /// <returns>业务操作结果</returns>
        public async Task<OperationResult> DeleteSalers(params Guid[] ids)
        {
            return await SalerStore.DeleteAsync(ids);
        }

    }
}